

***********************************;
** Output hedis2012.sas7bdat      *;
***********************************;

options ls=76 nofmterr;

libname raw '/data/Medicare_P01_2009/data/HEDIS/rawdata';
libname new '/data/Medicare_P01_2009/data/HEDIS/sasdata';


data a0; set new.hedis2012s;

      id_num=_n_;

     data raw.linkid2012; set a0;
          keep id_num hic_number;

data b0; set a0;

      *******************************************************;
      **  Clean up HEDIS measures based on specification   **;
      *******************************************************;

      **--- Set Missing Information to . ---**;

      array list1  ABA_D     ABA_N     COL_D     COL_N     BCS_D     BCS_N     OMW_D     OMW_N     CBP_D     CBP_N         
                   PBH_D     PBH_N     CMC_D     CMC_N1    CMC_N2    CDC_D1    CDC_N1    CDC_D2    CDC_N2
                   CDC_D3    CDC_N3    CDC_D4    CDC_N4    CDC_D5    CDC_N5    CDC_D6    CDC_N6    CDC_D7    CDC_N7    
                   CDC_D8    CDC_N8    CDC_D9    CDC_N9    SPR_D     SPR_N     AMM_D     AMM_N1    AMM_N2  
                   GSO_D     GSO_N     ART_D     ART_N     MPM_D1    MPM_N1    MPM_D2    MPM_N2    MPM_D3    MPM_N3    
                   MPM_D4    MPM_N4    DAE_D     DAE_N1    DAE_N2    
                   DDE_D_HOF     DDE_N_HOF      DDE_D_DEMEN    DDE_N_DEMEN    DDE_D_CRF    DDE_N_CRF     
                   AAP_D_20_44   AAP_N_20_44    AAP_D_45_64    AAP_N_45_64    AAP_D_65     AAP_N_65         
                   IET_D_13_17   IET_NI_13_17   IET_NE_13_17   IET_D_18       IET_NI_18    IET_NE_18 
                   IAD_N_SVCANY  IAD_N_SVCIP    IAD_N_SVCINT   IAD_N_SVCAMB
                   MPT_N_ANYMHS  MPT_N_IPMHS    MPT_N_IMHS     MPT_N_EDHS ;
      do over list1; if list1<0 or list1>=9 then list1=.; end; 

      array list2  PCE_D  PCE_N1   PCE_N2   FUH_D   FUH_N1   FUH_N2;
      do over list2; if list2<0 or list2>=99 then list2=.; end;

      array list3  FSP_N_BWLS    FSP_N_CABG    FSP_N_PTCA   FSP_N_CC      FSP_N_CE      FSP_N_OCH    FSP_N_CCH
                   FSP_N_BS      FSP_N_AH      FSP_N_VH     FSP_N_PROS    FSP_N_THR     FSP_N_TKR    FSP_N_MAST       
                   FSP_N_LUMP    IPU_T_ACDI    IPU_T_ACDY   IPU_T_ACMEDI  IPU_T_ACMEDY  IPU_T_ACSDI  IPU_T_ACSDY      
                   IPU_T_ACMADI  IPU_T_ACMADY  AMB_T_OV     AMB_T_ED ;
      do over list3; if list3<0 or list3>=999 then list3=.; end;

      array list4   ABX_T_RX      ABX_T_RXDY     ABX_T_RXCRN    ABX_T_QUINO   ABX_T_CEPHA   ABX_T_AZITH
                    ABX_T_AMOXI   ABX_T_KETOL    ABX_T_CLIND    ABX_T_CMISC   ABX_T_ABSOR   ABX_T_AMINO
                    ABX_T_1GNCE   ABX_T_LINCO    ABX_T_MACRO    ABX_T_PENIC   ABX_T_TETRA   ABX_T_MISC ;
      do over list4; if list4<0 or list4>=9999 then list4=.;  end;

      if ABA_D = 0 AND ABA_N >0 THEN ABA_D=.; IF ABA_D<=0 then ABA_N = . ; 
      if COL_D = 0 AND COL_N >0 THEN COL_D=.; IF COL_D<=0 then COL_N = . ;
      if BCS_D = 0 AND BCS_N >0 THEN BCS_D=.; IF BCS_D<=0 then BCS_N = . ;    
      if OMW_D = 0 AND OMW_N >0 THEN OMW_D=.; IF OMW_D<=0 then OMW_N = . ;
      if CBP_D = 0 AND CBP_N >0 THEN CBP_D=.; IF CBP_D<=0 then CBP_N = . ;
      if PBH_D = 0 AND PBH_N >0 THEN PBH_D=.; IF PBH_D<=0 then PBH_N = . ;
      if CMC_D = 0 AND (CMC_N1>0 OR CMC_N2>0) THEN CMC_D=.; IF CMC_D<=0 then do; CMC_N1 = .;  CMC_N2 = .;  end;

      if CDC_D1 = 0 AND CDC_N1>0 THEN CDC_D1=.; IF CDC_D1<=0 then CDC_N1 = . ;
      if CDC_D2 = 0 AND CDC_N2>0 THEN CDC_D2=.; IF CDC_D2<=0 then CDC_N2 = . ;
      if CDC_D3 = 0 AND CDC_N3>0 THEN CDC_D3=.; IF CDC_D3<=0 then CDC_N3 = . ;
      if CDC_D4 = 0 AND CDC_N4>0 THEN CDC_D4=.; IF CDC_D4<=0 then CDC_N4 = . ;
      if CDC_D5 = 0 AND CDC_N5>0 THEN CDC_D5=.; IF CDC_D5<=0 then CDC_N5 = . ;    
      if CDC_D6 = 0 AND CDC_N6>0 THEN CDC_D6=.; IF CDC_D6<=0 then CDC_N6 = . ;
      if CDC_D7 = 0 AND CDC_N7>0 THEN CDC_D7=.; IF CDC_D7<=0 then CDC_N7 = . ;
      if CDC_D8 = 0 AND CDC_N8>0 THEN CDC_D8=.; IF CDC_D8<=0 then CDC_N8 = . ;   
      if CDC_D9 = 0 AND CDC_N9>0 THEN CDC_D9=.; IF CDC_D9<=0 then CDC_N9 = . ;
   
      if SPR_D = 0  AND SPR_N>0  THEN CDC_D1=.; IF SPR_D<=0 then SPR_N = . ; 
 
      if AMM_D = 0 AND (AMM_N1>0 OR AMM_N2>0) THEN AMM_D=.; IF AMM_D<=0 then do; AMM_N1 = .; AMM_N2 = .; end;
      if GSO_D = 0 AND GSO_N>0 THEN GSO_D=.; IF GSO_D<=0 then GSO_N = . ;
      if ART_D = 0 AND ART_N>0 THEN ART_D=.; IF ART_D<=0 then ART_N = . ;
 
      if MPM_D1 = 0 AND MPM_N1>0 THEN MPM_D1=.; IF MPM_D1<=0 then MPM_N1 = . ;
      if MPM_D2 = 0 AND MPM_N2>0 THEN MPM_D2=.; IF MPM_D2<=0 then MPM_N2 = . ;
      if MPM_D3 = 0 AND MPM_N3>0 THEN MPM_D3=.; IF MPM_D3<=0 then MPM_N3 = . ;
      if MPM_D4 = 0 AND MPM_N4>0 THEN MPM_D4=.; IF MPM_D4<=0 then MPM_N4 = . ;    

      if DAE_D = 0 AND (DAE_N1>0 OR DAE_N2>0) THEN DAE_D=.; IF DAE_D=. then do; DAE_N1 = .; DAE_N2 = .; end;
 
      if DDE_D_HOF = 0   AND DDE_N_HOF>0   THEN DDE_D_HOF=.;   IF DDE_D_HOF <=0   then DDE_N_HOF = . ;
      if DDE_D_DEMEN = 0 AND DDE_N_DEMEN>0 THEN DDE_D_DEMEN=.; IF DDE_D_DEMEN <=0 then DDE_N_DEMEN = . ;
      if DDE_D_CRF = 0   AND DDE_N_CRF>0   THEN DDE_D_CRF=.;   IF DDE_D_CRF <=0   then DDE_N_CRF = .;

      if AAP_D_20_44 = 0 AND AAP_N_20_44>0 THEN AAP_D_20_44=.; IF AAP_D_20_44<=0 then AAP_N_20_44 = . ;    
      if AAP_D_45_64 = 0 AND AAP_N_45_64>0 THEN AAP_D_45_64=.; IF AAP_D_45_64<=0 then AAP_N_45_64 = . ;   
      if AAP_D_65 = 0    AND AAP_N_65>0    THEN AAP_D_65=.;    IF AAP_D_65<=0    then AAP_N_65 = .;

      if IET_D_13_17 = 0 AND (IET_NI_13_17>0 OR IET_NE_13_17>0) THEN IET_D_13_17=.; IF IET_D_13_17<=0 then do; IET_NI_13_17 = .;  IET_NE_13_17 = .; end;
      if IET_D_18 = 0    AND (IET_NI_18>0 OR IET_NE_18>0)       THEN IET_D_18=.;    IF IET_D_18<=0    then do; IET_NI_18 = .;     IET_NE_18 = .;    end;
     
      if PCE_D = 0 AND (PCE_N1>0 OR PCE_N2>0) THEN PCE_D=.; IF PCE_D<=0 then do; PCE_N1 = .; PCE_N2 = .; end;   
      if FUH_D = 0 AND (FUH_N1>0 OR FUH_N2>0) THEN FUH_D=.; IF FUH_D<=0 then do; FUH_N1 = .; FUH_N2 = .; end;


             *** Labels for Care Quality Measures ****; 
         
         Label ABA_D ='Denominator for Adult BMI Assessment';
         Label ABA_N ='Numerator for Adult BMI Assessment';

         Label COL_D ='Denominator for Colorectal Cancer Screening';
         Label COL_N ='Numerator for Colorectal Cancer Screening';

         Label BCS_D ='Denominator for Breast Cancer Screening: 52-69 Years';
         Label BCS_N ='Numerator for Breast Cancer Screening: 52-69 Years';

         Label OMW_D  ='Denominator for Osteoporosis Management in Women Who Had a Fracture';
         Label OMW_N  ='Numerator for Osteoporosis Management in Women Who Had a Fracture';
 
         Label CBP_D  ='Denominator for Controlling High Blood Pressure';
         Label CBP_N  ='Numerator for Controlling High Blood Pressure';
         Label PBH_D  ='Denominator for Persistence of Beta-Blocker Treatment After a Heart Attack';
         Label PBH_N  ='Numerator for Persistence of Beta-Blocker Treatment After a Heart Attack';

         Label CMC_D  ='Denominator for Cholesterol Management for Pts w/Cardio Conditions (CMC)';
         Label CMC_N1 ='Numerator 1 for CMC: LDL-C screening';
         Label CMC_N2 ='Numerator 2 for CMC: LDL-C level of <100 mg/dL';

         Label CDC_D1 ='Denominator 1 for Comprehensive Diabetes Care: HbA1c Testing';
         Label CDC_N1 ='Numerator 1 for Comprehensive Diabetes Care: HbA1c Testing';
         Label CDC_D2 ='Denominator 2 for Comprehensive Diabetes Care: HbA1c Poor Control >9%';
         Label CDC_N2 ='Numerator 2 for Comprehensive Diabetes Care: HbA1c Poor Control >9%';
         Label CDC_D3 ='Denominator 3 for Comprehensive Diabetes Care: HbA1c Good Control <7%';
         Label CDC_N3 ='Numerator 3 for Comprehensive Diabetes Care: HbA1c Good Control <7%';
         Label CDC_D4 ='Denominator 4 for Comprehensive Diabetes Care: Eye exam (retinal) performed';
         Label CDC_N4 ='Numerator 4 for Comprehensive Diabetes Care: Eye exam (retinal) performed';
         Label CDC_D5 ='Denominator 5 for Comprehensive Diabetes Care: LDL-C Screening';
         Label CDC_N5 ='Numerator 5 for Comprehensive Diabetes Care: LDL-C Screening';
         Label CDC_D6 ='Denominator 6 for Comprehensive Diabetes Care: LDL-C Control <100mg/dL';
         Label CDC_N6 ='Numerator 6 for Comprehensive Diabetes Care: LDL-C Control <100mg/dL';
         Label CDC_D7 ='Denominator 7 for Comprehensive Diabetes Care: Medical Attention for Nephropathy';  
         Label CDC_N7 ='Numerator 7 for Comprehensive Diabetes Care: Medical Attention for Nephropathy'; 
         Label CDC_D8 ='Denominator 8 for Comprehensive Diabetes Care: Blood pressure control <130/80 mm Hg';
         Label CDC_N8 ='Numerator 8 for Comprehensive Diabetes Care: Blood pressure control <130/80 mm Hg';
         Label CDC_D9 ='Denominator 9 for Comprehensive Diabetes Care: Blood pressure control <140/90 mm Hg'; 
         Label CDC_N9 ='Numerator 9 for Comprehensive Diabetes Care: Blood pressure control <140/90 mm Hg';

         Label SPR_D  ='Denominator for Use of Spirometry Testing in Assessment/Diagnosis of COPD';
         Label SPR_N  ='Numerator for Use of Spirometry Testing in Assessment/Diagnosis of COPD';

         Label PCE_D  ='Denominator for Pharmacotherapy Management of COPD Exacerbation (PCE)';
         Label PCE_N1 ='Numerator 1 for PCE: Systemic Corticosteroid'; 
         Label PCE_N2 ='Numerator 2 for PCE: Bronchodilator'; 

         Label FUH_D  ='Denominator for Follow-Up after Hospitalization for Mental Illness (FUH)';
         Label FUH_N1 ='Numerator 1 for FUH: 30-day follow-up';
         Label FUH_N2 ='Numerator 2 for FUH: 7-day follow-up';

         Label AMM_D  ='Denominator for Antidepressant Medication Management (AMM)';
         Label AMM_N1 ='Numerator 1 for AMM: Optimal Practitioner Contacts for Medication Management';
         Label AMM_N2 ='Numerator 2 for AMM: Effective Acute Phase Treatment';

         Label GSO_D  ='Denominator for Glaucoma Screening in Older Adults (GSO)';
         Label GSO_N  ='Numerator for Glaucoma Screening in Older Adults (GSO)';

         Label ART_D  ='Denominator for Disease Modifying Anti-Rheumatic Drug Therapy for Rheumatoid Arthritis';
         Label ART_N  ='Numerator for Disease Modifying Anti-Rheumatic Drug Therapy for Rheumatoid Arthritis';
    
         Label MPM_D1 ='Denominator 1 for Monitor Persistent Medications: ACE Inhibitors or ARBs Medications';
         Label MPM_N1 ='Numerator 1 for Monitor Persistent Medications: ACE Inhibitors or ARBs Medications';
         Label MPM_D2 ='Denominator 2 for Monitor Persistent Medications: Digoxin';
         Label MPM_N2 ='Numerator 2 for Monitor Persistent Medications: Digoxin';
         Label MPM_D3 ='Denominator 3 for Monitor Persistent Medications: Diuretics';
         Label MPM_N3 ='Numerator 3 for Monitor Persistent Medications: Diuretics';
         Label MPM_D4 ='Denominator 4 for Monitor Persistent Medications: Anticonvulsants'; 
         Label MPM_N4 ='Numerator 4 for Monitor Persistent Medications: Anticonvulsants';

         Label DAE_D  ='Denominator for Use of High-Risk Medications in the Elderly (DAE)';
         Label DAE_N1 ='Numerator 1 for DAE: At Least One Prescription'; 
         Label DAE_N2 ='Numerator 2 for DAE: At Least Two Prescriptions'; 

              *** DDE: Drug-Disease Interactions in Elderly ***;

         label DDE_D_HOF   ='Denominator 1 for DDE: History of Falls + Tricyclic Antidepressants/Antipsychotics/Sleep Agents'; 
         label DDE_N_HOF   ='Numerator 1 for DDE: History of Falls + Tricyclic Antidepressants/Antipsychotics/Sleep Agents'; 
         label DDE_D_DEMEN ='Denominator 2 for DDE: Dementia + Tricyclic Antidepressants/Anticholineric Agents';
         label DDE_N_DEMEN ='Numerator 2 for DDE: Dementia + Tricyclic Antidepressants/Anticholineric Agents';
         label DDE_D_CRF   ='Denominator 3 for DDE: Chronic Renal Failure + Nonaspirin NSAIDs/Cox-2 Selective NSAIDs';
         label DDE_N_CRF   ='Numerator 3 for DDE: Chronic Renal Failure + Nonaspirin NSAIDs/Cox-2 Selective NSAIDs';
 
         label AAP_D_20_44 ='Denominator for Adults Access to Preventive/Ambulatory Health Serv: Ages 20-44';
         label AAP_N_20_44 ='Numerator for Adults Access to Preventive/Ambulatory Health Serv: Ages 20-44'; 
         label AAP_D_45_64 ='Denominator for Adults Access to Preventive/Ambulatory Health Serv: Ages 45-64'; 
         label AAP_N_45_64 ='Numerator for Adults Access to Preventive/Ambulatory Health Serv: Ages 45-64'; 
         label AAP_D_65    ='Denominator for Adults Access to Preventive/Ambulatory Health Serv: Ages 65+'; 
         label AAP_N_65    ='Numerator for Adults Access to Preventive/Ambulatory Health Serv: Ages 65+'; 

              *** AOD: Alcohol and Other Drug Dependence ***;

         label IET_D_13_17  ='Denominator for Initiation and Engagement of AOD Treatment: 13-17 years';
         label IET_NI_13_17 ='Numerator for: Initiation of AOD Treatment -13-17 years';
         label IET_NE_13_17 ='Numerator for: Engagement of AOD Treatment -13-17 years';
         label IET_D_18     ='Denominator for Initiation/Engagement of AOD Dependence Treatment: 18+ years';
         label IET_NI_18    ='Numerator for: Initiation of AOD Treatment-18+ years';
         label IET_NE_18    ='Numerator for: Engagement of AOD Treatment-18+ years';

              *** FSP variables - Numerators Only ***;

        label FSP_N_BWLS ='Frequent Selected Procedures: Bariatric Weight Loss Surgery';
        label FSP_N_CABG = 'Frequency of Selected Procedure: CABG';
        label FSP_N_PTCA = 'Frequency of Selected Procedure: PTCA';
        label FSP_N_CC   = 'Frequency of Selected Procedure: Cardiac Catheterization';
        label FSP_N_CE   = 'Frequency of Selected Procedure: Carotid Endarterectomy';
        label FSP_N_OCH  = 'Frequency of Selected Procedure: Open Cholecystectomy';
        label FSP_N_CCH  = 'Frequency of Selected Procedure: Closed Cholecystectomy';
        label FSP_N_BS   = 'Frequency of Selected Procedure: Back Surgery';
        label FSP_N_AH   = 'Frequency of Selected Procedure: Abdominal Hysterectomy';
        label FSP_N_VH   = 'Frequency of Selected Procedure: Vaginal Hysterectomy';
        label FSP_N_PROS = 'Frequency of Selected Procedure: Prostatectomy';
        label FSP_N_THR  = 'Frequency of Selected Procedure: Total Hip Replacement (THR)';
        label FSP_N_TKR  = 'Frequency of Selected Procedure: Total Knee Replacement (TKR)';
        label FSP_N_MAST = 'Frequency of Selected Procedure: Mastectomy';
        label FSP_N_LUMP = 'Frequency of Selected Procedure: Lumpectomy';

        label IPU_T_ACDI   = 'Inpat Utili Gen Hosp/Acute Care- Discharges';
        label IPU_T_ACDY   = 'Inpat Utili Gen Hosp/Acute Care- Days';
        label IPU_T_ACSDI  = 'Inpat Utili Gen Hosp/Acute Care- Surgery Discharges';
        label IPU_T_ACSDY  = 'Inpat Utili Gen Hosp/Acute Care- Surgery Days';
        label IPU_T_ACMEDI = 'Inpat Utili Gen Hosp/Acute Care- Medicine Discharges';
        label IPU_T_ACMEDY = 'Inpat Utili Gen Hosp/Acute Care- Medicine Days';
        label IPU_T_ACMADI = 'Inpat Utili Gen Hosp/Acute Care- Maternity Discharges';
        label IPU_T_ACMADY = 'Inpat Utili Gen Hosp/Acute Care- Maternity Days';

        label AMB_T_OV    = 'Ambulatory Care- Outpatient Visits';
        label AMB_T_ED    = 'Ambulatory Care- Emergency Department Visits';

        label IAD_N_SVCANY = 'Alcohol/Other Drug Serv: Pct Members Receiv Any Serv';
        label IAD_N_SVCIP  = 'Alcohol/Other Drug Serv: Pct Members Receiv Inpatient Serv';
        label IAD_N_SVCINT = 'Alcohol/Other Drug Serv: Pct Members Receiv Intensive Outpatient Serv';
        label IAD_N_SVCAMB = 'Alcohol/Other Drug Serv: Pct Members Receiv Outpatient and ED Serv';

        label MPT_N_ANYMHS = 'Mental Health Utilization: Pct Members Receiv Any Serv';
        label MPT_N_IPMHS  = 'Mental Health Utilization: Pct Members Receiv Inpatient Serv';
        label MPT_N_IMHS   = 'Mental Health Utilization: Pct Members Receiv Intensive Outpatient Serv';
        label MPT_N_EDHS   = 'Mental Health Utilization: Pct Members Receiv Outpatient and ED Serv';

        label ABX_T_RX     = 'Total Number of Antibiotic Prescriptions';
        label ABX_T_RXDY   = 'Total days supplied for all antibiotic prescriptions';
        label ABX_T_RXCRN  = 'Total number of prescriptions for antibiotics of concern';
        label ABX_T_QUINO  = 'Antibiotics of Concern-Quinolones';
        label ABX_T_CEPHA  = 'Antibiotics of Concern-Cephalosporins 2nd- 4th Generation';
        label ABX_T_AZITH  = 'Antibiotics of Concern-Azithromycin and Clarithromycin';
        label ABX_T_AMOXI  = 'Antibiotics of Concern-Amoxicillin/Clavulanate';
        label ABX_T_KETOL  = 'Antibiotics of Concern-Ketolides';
        label ABX_T_CLIND  = 'Antibiotics of Concern-Clindamycin';
        label ABX_T_CMISC  = 'Miscellaneous Antibiotics of Concern';
        label ABX_T_ABSOR  = 'All Other Antibiotics -Absorbable Sulfonamides';
        label ABX_T_AMINO  = 'All Other Antibiotics -Aminoglycosides';
        label ABX_T_1GNCE  = 'All Other Antibiotics -FirstGeneration Cephalosporins';
        label ABX_T_LINCO  = 'All Other Antibiotics -Lincosamides (other than Clindamycin)';
        label ABX_T_MACRO  = 'All Other Antibiotics -Macrolides (other than Azithromycin and Clarithromycin)';
        label ABX_T_PENIC  = 'All Other Antibiotics -Penicillins';
        label ABX_T_TETRA  = 'All Other Antibiotics -Tetracyclines';
 
        proc sort; by hic_number;       

data denom0; set raw.denom2012hedis;

      proc sort; by hic_number;

data new.hedis2012; merge b0(in=ok) denom0; by hic_number;

     if ok;

     proc contents varnum data=new.hedis2012;
          title 'HEDIS2012 analysis dataset';

     proc freq data=new.hedis2012;
          tables denom_flag plantypec org_id;
          title 'HEDIS2012 Analysis Dataset';

endsas;
